<?php

namespace app\common\model;

use think\Model;


/**
 * 商品模型
 */
class Goods extends Model
{

    public static function getType(){
        $data = [
            ['id'=>'0','name'=>'自己买'],
            ['id'=>'1','name'=>'送一人'],
            ['id'=>'2','name'=>'群发多人抢']
        ];

        return $data;
    }

    /**
     * 加入足迹
     * @param $goods_id,$user_id
     */
    public static function addzuji($goods_id,$user_id){

        $config = \think\Config::get('redis');
        $client = new \Predis\Client($config);
        $key = "viewHistory-" . $user_id;

//        //如果已存在, 则删除之前的
//        $client->lrem($key,$goods_id,0);
        $client->lrem($key,1,$goods_id);
//
        //超过了需要展示的最大数量，删除最早添加的记录
        if($client->llen($key) >= 30){
            $client->lpop($key);
        }

        //加入队列
        $client->rpush($key,$goods_id);
    }

}